package com.ljph.kit;

import com.jfinal.kit.StrKit;

import java.util.regex.Pattern;

/**
 * Created by yuzhou on 16/8/11.
 */
public class RegExpKit {

  /**
   * 验证正整数，不包含0
   *
   * @param integer
   * @return
   */
  public static boolean checkPositiveInteger(String integer) {
    if (integer == null) {
      return false;
    }
    String regex = "^[1-9]\\d*$";
    return Pattern.matches(regex, integer);
  }

  public static boolean checkVideo(String contentType) {
    if (StrKit.isBlank(contentType)) {
      return false;
    }

    String regex = "^video/[a-zA-Z0-9-]+$";
    return Pattern.matches(regex, contentType);
  }

  public static boolean checkImage(String contentType) {
    if (StrKit.isBlank(contentType)) {
      return false;
    }

    String regex = "^image/[a-zA-Z0-9-]+$";
    return Pattern.matches(regex, contentType);
  }

  public static boolean checkJpeg(String contentType) {
    if (StrKit.isBlank(contentType)) {
      return false;
    }
    String regex = "^image/jpe?g$";
    return Pattern.matches(regex, contentType);
  }

  public static boolean checkPng(String contentType) {
    if (StrKit.isBlank(contentType)) {
      return false;
    }
    String regex = "^image/png$";
    return Pattern.matches(regex, contentType);
  }
}
